<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";

// -----------------------------------------------------------------------------
?>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title>重置数据库</title>
    <base target="_self">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="../resources/bootstrap-5.2.0-beta1-dist/css/bootstrap.min.css">
    <style>
        p {
            margin-bottom: 5px;
        }
        ol {
            margin-bottom: 5px;
        }
    </style>
</head>
<body>

<!-- ----------------------------------------------------------------------- -->

<script src="../resources/bootstrap-5.2.0-beta1-dist/js/bootstrap.min.js"></script>
<script src="../resources/jQuery/jquery-3.5.1.js"></script>
<?php include "../globalNavbar.php"; ?>

<!-- ----------------------------------------------------------------------- -->

<!--div:container start-->
<div class="container container-fluid mb-5">

    <!-- 导航栏 开始 -->
    <div class="mt-3">
        <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a class="text-decoration-none" href="<?php echo $homepage; ?>">首页</a></li>
                <li class="breadcrumb-item active">重置数据库</li>
            </ol>
        </nav>
    </div>
    <!-- 导航栏 结束 -->

    <div class="mt-2">

        <!-- --------------------------------------------------------------- -->

        <div class="mt-0 alert alert-warning" role="alert">
            <h4 class="alert-heading">注意：</h4>
            <?php
            $msg = "";
            if ($dbReCreatable == "true") {

                $msg = <<<BBB
                当前数据库状态为<span class="text-danger">「允许被重置」</span>。本次重置操作完成后，应及时变更数据库状态为<span class="text-info">「不允许被重置」</span>。
                BBB;

            } else {

                $msg = <<<BBB
                当前数据库状态为<span class="text-danger">「不允许被重置」</span>。在日常使用中，应始终保持数据库处于这一状态。
                BBB;

            }
            ?>

            <p>这将清空数据库中存储的全部数据，且该操作<span class="text-danger">无法撤消</span>。</p>
            <p>为了避免失误操作导致数据库被清空，请按以下步骤重置数据库：</p>
            <ol>
                <li>在配置文件 <span class="text-info">config/config.php</span> 中修改变量 <span class="text-info">$dbReCreatable</span> 的值，允许数据库被重置。<?php echo $msg; ?></li>
                <li>在下方输入框中输入 <span class="text-info">sure</span> 以确认重置数据库。</li>
            </ol>

        </div>

        <!-- --------------------------------------------------------------- -->

        <div class="mt-2">
            <input id="inputSure" type="text" class="form-control">
        </div>

        <div class="mt-3">
            <button id="btnSureToRecreateDB" type="button" class="btn btn-outline-primary">确认</button>
        </div>

        <!-- --------------------------------------------------------------- -->

    </div>

</div>
<!--div:container end-->

<!-- ----------------------------------------------------------------------- -->

<script>

    $("#btnSureToRecreateDB").on("click", function () {

        var inputtedContent = $("#inputSure").val()
        $("#inputSure").val("")

        if (inputtedContent == "sure") {

            var url = "DBRecreate.php"

            $.get(url)
                .done(function( data ) {
                    alert(data)
                })
                .fail(function () {
                    alert("请求失败。")
                });

        }

    })

</script>

<!-- ----------------------------------------------------------------------- -->

</body>
</html>
